package com.watson.grpc.demoa;

import com.watson.grpc.config.GrpcClientMananer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author watson
 * @Date 2022/7/4 15:20
 * @Description: TODO
 * @Version 1.0
 */
@Component
public class HelloWorldClient {
    @Autowired
    private GrpcClientMananer grpcClientMananer;
    public void call(){
        ManagedChannel channel = grpcClientMananer.getChannel();
        HelloWorld.NameRequestOrBuilder nameRequestOrBuilder = HelloWorld.NameRequest.newBuilder();
        ((HelloWorld.NameRequest.Builder) nameRequestOrBuilder).setName("Geek");
        HelloWorldServiceGrpc.HelloWorldServiceBlockingStub stub = HelloWorldServiceGrpc.newBlockingStub(channel);
        HelloWorld.EchoResponse echoResponse = stub.welcome(((HelloWorld.NameRequest.Builder) nameRequestOrBuilder).build());
        System.out.println(echoResponse.getMergename());
    }
}
